package game.screen;

import game.logic.GameControl;
import game.shared.Constants;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class ScreenMenu extends AbsScreen {

	private Texture texture;
	private Texture tMenu;
//	private Texture tMenuSelect;
	private int iSelect;
	private BitmapFont font;
	
	String s;
	private int count;
	public ScreenMenu(GameControl _gameControl) {
		super(_gameControl);
		texture = new Texture(Constants.MENU_BACKGROUND_TEXTURE);
		tMenu = new Texture(Constants.MENU_TEXTURE);
		iSelect = 0;
		font = new BitmapFont();
		s = new String();
		s = "null";
		count = 0;
		//System.out.println("Left click to go to gameplaying1");
		//System.out.println("Enter num 2 to go to gameplaying2");
	}
	
	@Override
	public void update() {
		count ++;
		
//		if(Gdx.input.isKeyPressed(Keys.NUM_2)){
//			//System.out.println("Go to gameplaying2");
//			this.gameControl.setScreen(new ScreenPlaying(this.gameControl));
//		}
		
		//Left click to go screen playing
		if(Gdx.input.isButtonPressed(Input.Buttons.LEFT) || Gdx.input.isKeyPressed(Keys.ENTER))
			this.gameControl.setScreen(new ScreenPlaying(this.gameControl));
		if(Gdx.input.isKeyPressed(Keys.UP))
		{
			if(count>10)
			{
				iSelect = iSelect == 0 ? 5 : iSelect-1;
				count = 0;
			}
		}
		if(Gdx.input.isKeyPressed(Keys.DOWN))
		{
			if(count>10)
			{
				iSelect = iSelect == 5 ? 0 : iSelect+1;
				count = 0;
			}
		}
		
	}
	
	@Override
	public void render(float arg0) {
		if(sb!= null)
		{
			sb.begin();
			
			if(texture != null)
				sb.draw(texture, 0, (Constants.SCREEN_HEIGHT - texture.getHeight())/2);
			
			int itemW = 90;
			int itemH = 22;
			TextureRegion regionMenu = new TextureRegion(tMenu, 0, 0, itemW, itemH*6);
			sb.draw(regionMenu, 50, 100, itemW, itemH*6);
			
			TextureRegion regionMenuSelect = new TextureRegion(tMenu, itemW+1, iSelect*itemH, itemW, itemH);
			sb.draw(regionMenuSelect, 50, 100+(5-iSelect)*itemH, itemW, itemH);
			
			
			font.draw(sb, String.valueOf(Gdx.graphics.getDeltaTime()), Constants.SCREEN_WIDTH-100, Constants.SCREEN_HEIGHT-100);
			font.draw(sb, s, Constants.SCREEN_WIDTH-200, Constants.SCREEN_HEIGHT-120);
			
			sb.end();
		}
	}
	
}
